<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

    <div id="demo1"></div>
    <button>结束进程</button>

    <script src="../../js/jquery-3.2.1.js"></script>

    <script>
        $(function () {
            if (typeof (Worker) !== "undefined") {
                var worker = new Worker('webWorker.js');
                // worker.postMessage('Hello');
                worker.onmessage = function (e) {
                    $('#demo1').text(e.data);
                };
                worker.onerror = function (e) {
                    console.log("error at " + e.filename +":" + e.lineno + e.message)
                }
                $('button').on('click',function(){
                    worker.terminate();
                })
            } else {
                alert('不支持webWorker')
            }
        })
    </script>

</body>

</html>